# -*- coding: utf-8 -*-
# @Time : 2022/8/11 下午2:38
# @Author : WangYunfei
# @FileName: demo.py
# @Email: yunfei.wang@innvote.com
import requests


class DHL(object):

    def __init__(self):
        self.cookies = {}
        self.headers = {
            "authority": "www.dhl.com",
            "accept": "*/*",
            "accept-encoding": "gzip, deflate, br",
            "accept-language": "zh-CN,zh;q=0.9",
            "cache-control": "no-cache",
            "content-type": "application/json",
            "origin": "https://www.dhl.com",
            "pragma": "no-cache",
            "referer": "https://www.dhl.com/us-en/home/tracking/tracking-ecommerce.html?tracking-id=9374810912400489575369",
            "sec-ch-ua": "\"Chromium\";v=\"104\", \" Not A;Brand\";v=\"99\", \"Google Chrome\";v=\"104\"",
            "sec-ch-ua-mobile": "?0",
            "sec-ch-ua-platform": "\"Windows\"",
            "sec-fetch-dest": "empty",
            "sec-fetch-mode": "cors",
            "sec-fetch-site": "same-origin",
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36",
            "x-sec-clge-req-type": "ajax"
        }
        self.sensor_data = {"sensor_data":"7a74G7m23Vrp0o5c9363701.75-1,2,-94,-100,Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36,uaend,12147,20030107,zh-CN,Gecko,5,0,0,0,408487,6519388,1920,1040,1920,1080,492,937,1920,,cpen:0,i1:0,dm:0,cwen:0,non:1,opc:0,fc:0,sc:0,wrc:1,isc:0,vib:1,bat:1,x11:0,x12:1,8102,0.07409380737,830098259694,0,loc:-1,2,-94,-131,Mozilla/5.0 (Windows;10.0.0;x86;64;) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.81 Safari/537.36-1,2,-94,-101,do_en,dm_en,t_en-1,2,-94,-105,0,0,0,0,2343,113,0;0,-1,1,1,4770,1101,0;0,-1,1,1,4766,1101,0;0,0,0,0,2327,113,0;0,-1,1,1,4776,1101,0;0,0,0,0,2358,113,0;0,-1,1,1,4867,1101,0;0,0,0,0,2327,113,0;-1,2,-94,-102,0,0,0,0,2343,113,0;0,-1,1,1,4770,1101,0;0,-1,1,1,4766,1101,0;0,0,0,0,2327,113,0;0,-1,1,1,4776,1101,0;0,0,0,0,2358,113,0;0,-1,1,1,4867,1101,0;0,0,0,0,2327,113,0;0,-1,0,0,2108,2108,0;-1,2,-94,-108,-1,2,-94,-110,0,1,2060,489,292;1,1,2062,481,295;2,1,2066,477,297;3,1,2068,464,300;4,1,2070,461,302;5,1,2072,455,304;6,1,2074,451,306;7,1,2077,444,309;8,1,2079,441,309;9,1,2080,437,311;10,1,2082,431,313;11,1,2084,428,315;12,1,2086,422,317;13,1,2088,418,318;14,1,2090,413,320;15,1,2092,409,322;16,1,2094,407,323;17,1,2096,403,324;18,1,2098,400,326;19,1,2100,397,328;20,1,2102,394,328;21,1,2105,388,331;22,1,2106,385,332;23,1,2109,382,334;24,1,2111,380,334;25,1,2112,378,336;26,1,2114,376,337;27,1,2116,374,337;28,1,2119,372,338;29,1,2120,370,340;30,1,2122,368,340;31,1,2125,367,340;32,1,2126,365,342;33,1,2128,364,342;34,1,2130,363,342;35,1,2132,362,343;36,1,2134,361,344;37,1,2138,360,344;38,1,2141,359,345;39,1,2142,358,345;40,1,2146,357,345;41,1,2148,357,346;42,1,2150,357,347;43,1,2152,356,347;44,1,2154,355,347;45,1,2162,354,348;46,1,2170,353,348;47,1,2174,353,349;48,1,2178,352,349;49,1,2182,351,349;50,1,2184,351,350;51,1,2190,350,351;52,1,2198,349,351;53,1,2200,349,352;54,1,2204,348,352;55,1,2208,347,353;56,1,2214,346,353;57,1,2218,346,354;58,1,2220,345,354;59,1,2226,344,355;60,1,2228,343,355;61,1,2230,343,356;62,1,2234,342,356;63,1,2236,342,357;64,1,2238,341,357;65,1,2244,340,357;66,1,2246,339,358;67,1,2248,338,359;68,1,2252,337,360;69,1,2254,336,360;70,1,2258,335,361;71,1,2260,334,361;72,1,2262,334,362;73,1,2264,333,362;74,1,2266,332,363;75,1,2268,331,363;76,1,2272,330,364;77,1,2274,329,364;78,1,2276,328,364;79,1,2280,328,365;80,1,2283,327,365;81,1,2284,326,366;82,1,2286,325,366;83,1,2290,324,367;84,1,2294,322,367;85,1,2298,321,368;86,1,2302,320,368;87,1,2304,319,368;88,1,2306,318,368;89,1,2310,317,369;90,1,2312,316,369;91,1,2314,316,370;92,1,2316,315,370;93,1,2320,314,370;94,1,2322,313,370;95,1,2326,312,371;96,1,2328,311,371;97,1,2333,310,371;98,1,2334,309,371;99,1,2336,309,372;625,3,6297,460,550,1523;-1,2,-94,-117,-1,2,-94,-111,0,74,-1,-1,-1;-1,2,-94,-109,0,73,-1,-1,-1,-1,-1,-1,-1,-1,-1;-1,2,-94,-114,-1,2,-94,-103,-1,2,-94,-112,https://www.dhl.com/us-en/home/tracking/tracking-ecommerce.html?tracking-id=9374810912400489575369-1,2,-94,-115,1,302852,32,74,73,0,302967,6297,0,1660196519388,13,17760,0,626,2960,1,0,6298,225460,0,269D9221DDC85066D49F9BB8FFD22A9C~-1~YAAQR/6Yc5yVT4qCAQAAoH9siwincB9Gn+Mxut71mQQQzzA0xTeC+BRSGhu9fH9jGqdXYhZmZQy3QoxToswuDUVbQdQeVovCVRP+YwjB62joA27gxQlh9jJe4Nl4mppK7tQtB+O/s5zUWQO+UNXdKK2gv7jFXlwZxGoQ5jmyAyzJubpZZ0W5xecwfdTYzAaX5IgY2Q3Hiw5gjkHG/FX3KrG/+baBhBALMErori/f5odiBrBqvWGRl4Huy6H2EFOdzJiN0mzHnQc+M4vqPvCGBk1YuW7SWL0LT9UE01MiNVma9JpnHyPWdiqXElQDQ3QSfIDvfdjarlxwkYjoFzLXqtWGRCj1TZ1dDwNyo9CNDto6rMWBcYlfT5MARyI+jVpmSwr2VuX9YHKY4Jb+nFHerOOUkwuW/GMlKf7N6SQI~-1~-1~-1,39528,386,-2126157655,30261693,PiZtE,24949,84,0,-1-1,2,-94,-106,1,2-1,2,-94,-119,-1-1,2,-94,-122,0,0,0,0,1,0,0-1,2,-94,-123,-1,2,-94,-124,-1,2,-94,-126,-1,2,-94,-127,11321144241322243122-1,2,-94,-70,448809179;54595805;dis;,7;true;true;true;-480;true;24;24;true;false;-1-1,2,-94,-80,5355-1,2,-94,-116,1584211308-1,2,-94,-118,212021-1,2,-94,-129,2a9eadd8df3b18fb8899addb2a49d5c86d0b07d2f88b5d0032ff3803215b78b9,1,e6a6b62042f2333998b8357baa6fe8b776aaad3c0b1692df334f2afaf3954baf,Google Inc. (Intel),ANGLE (Intel, Intel(R) Iris(R) Xe Graphics Direct3D11 vs_5_0 ps_5_0, D3D11),fab37783e5c3bc89f876774bac442ad3e613f7dc5b769b19a8d4d8c6b80ef077,29-1,2,-94,-121,;2;5;0"}

    def jihuo_cookie(self, cookie):
        _url = "https://www.dhl.com/PzYAJi5hC3/SLTYgEqfNj/ENb7krLp5hDu/OxtkPw/Qzt5Mi/ciOQAB"
        res = requests.post(url=_url, json=self.sensor_data, headers=self.headers, cookies=cookie)
        print(res.text, res.cookies)
        return res

    def utapi(self, cookie=dict()):
        _cookie = {
            # "bm_sz": "5AEC1A5419A8F05D7158B101EDBA257B~YAAQtArgeuuM+muCAQAASqGXixAliOlY3d+msADeinXIa6Zub7LiQxs81qws+jOhaHHgGxdqj2rLuvRv8/pxAzlG+rmyX54UXVS3bB//sazu4BX821vxxwdy0Kvuo4bqN9zHoLRI5DKV+G3mAUpJCuXpPjc8n1I1U72h2h7cfCAz892EYFLbwHaco42P7Nbex7xdGpBzp7afewtXIJCykDxvmbimG0ACa53Vp1PD05o66WMqxkZQjexxUZYQL5QxE3DSjHbimPUUeh9n7D/D8nU9n1PNaS79Wt2pCJtuh6lGCyqoVAw06DImaGfkfegWeggkmRDNEHf/drkLPdjOAoYCYF4v581f5+oC+ypDB29rvzX4qt3BJXI6p5Zejz+TGV1w7DJRDIlVrXGWEEg=~3355449~3487026",
            "tracking-id": "9374810912400489575369",
            "RT": "\"z=1&dm=www.dhl.com&si=aa1d7917-4008-4399-92a8-9d68312677cf&ss=l6onbyay&sl=1&tt=3q9&rl=1&nu=4cupivqj&cl=iiw8\"",
            # "_abck": "AA934553C3E9042C52E66615DDBA167A~-1~YAAQtArgeueW+muCAQAAZyyYiwiFGib0+RKFtKx3TFB9zxwRQfHE4Ts7O8YQ53SXNT9slayKU74pTOrVfo67dDIk27a1Eq3lEoN84OQEyjv8Nn4/pqcr6+tfADm14v5EJ5Pb8TeJsTwG3nSDTHJiAJtIn6HlYjdpd+KKCKp13hS3TZ0GNxJ+idhGBjJj2yufgWetudDzR4bs5/IaSN7JsBXnmHcucdlIcf39Ve+MYDOY64HqsOheD68jaj5uowh4O0IwOJS7RCuNRbxcv1jjnoN7E3CagZa+HA1AOe3Vk+CZMG11g/7fSCNHDQq1ACFxrt1o321LD4ohJpt4RBIuKdapHCDDzjz6SA9tDipFqRQZbSYNrMz0cvajuKETyALDb7dvx4NWoUXicN2hMZ/NpAePxvtN5wteUOB+syz5~-1~-1~-1",
            # "ak_bmsc": "D001B593E5526F85942169C7454CFBD8~000000000000000000000000000000~YAAQtArgeuiW+muCAQAAZyyYixDzJZrBy7Q122pR1IE8H3uv+cZpnshdqZiUyStIMa390f5dA+Zz/MMfxG0dmqpzfCnzTboyiIUezUDdxjx+eNbcXxp86Ml9YeELa28I7DByOluJKGz76A+zmMAISRlr7N0hP8ONoivKSYAhW5Y7vlahN2wLsw41PLvLCmE+4x2BJMw3LU6o7HlRHXWXRNSs85Wz6VRKEi890YwBWGrBrkaMs1GOeoX2e75HRp1cLcFgQDWSMjGshg51QUIBG4XL21k6YMUh1cCmfSmU7r2r0ZTkfc15dq+SNyvaq1ZnNCAMtENwI93DLgTuKHaK3dghNtrV42RIpqMztEHqgxQtpC4TEW3TrVZKFhyN1RDkoslWiqSuFUc=",
            "s_sq": "dhlglobalrolloutprod%3D%2526c.%2526a.%2526activitymap.%2526page%253DTrack%252520%252526%252520Trace%252520eCommerce%252520%25257C%252520DHL%2526link%253DTrack%2526region%253Dwcag-main-content%2526pageIDType%253D1%2526.activitymap%2526.a%2526.c%2526pid%253DTrack%252520%252526%252520Trace%252520eCommerce%252520%25257C%252520DHL%2526pidt%253D1%2526oid%253DTrack%2526oidt%253D3%2526ot%253DSUBMIT"
        }
        _cookie.update(cookie)

        _url = "https://www.dhl.com/utapi?trackingNumber=9374810912400489575369&language=en&requesterCountryCode=US"
        req = requests.get(url=_url, headers=self.headers, cookies=_cookie)
        print("utapi", req)
        print(dict(req.cookies))
        self.jihuo_cookie(dict(req.cookies))
        for k, v in dict(req.cookies).items():
            _cookie[k] = v

        print("___cookie", _cookie)
        req = requests.get(url=_url, headers=self.headers, cookies=_cookie)
        print("utapi222222", req, req.text)
        print(dict(req.cookies))



if __name__ == '__main__':
    dhl = DHL()
    # dhl.jihuo_cookie()
    c_cookie = {'_abck': 'AA934553C3E9042C52E66615DDBA167A~-1~YAAQtArgeow0AGyCAQAASYUIjAhI+nWfx3LMp0b60TWiFRYYghBBDUwTMslF/vw2D/yvj79ku7/3lZxq/oyvb/sNjRuJ9ni01vb3fbutPjv5Ysorh1Pma2uJVd8GpFQOb8GssPzr7kdYHs33+pIjhzFbNwI26FGFg0B36Y44g7rJJ14SGbRVcRL0iA3nSiu9q1ggZscN/6Kb34Vio2VTU8C3qCWGkgS/DT9/ulc4QRCPOm4jRMmeh3DLLM2J+77LNXkocxbMqg2oLBEO3pIKGUYFMjdBc8xzszjNZIJunHfbBGEeG+n5njw/nNE6S/1VCEA2QW1jycAieqt1cJH+xdjvV1bjGgUiG5r4o7DWXxgPDJg1JuzoCroEOjOjwUq/MWY9uMVA7KFyqbb8D5SUHYRCbjgm4YVMSz09dDOg~-1~-1~-1',
                'ak_bmsc': '1B61CBEF0A385CA6C533EA76DD3C1E10~000000000000000000000000000000~YAAQtArgeo00AGyCAQAASYUIjBA7mC83rxP3VGS6ooK0Dny7IiwQ5LKJcjBG6eSZWjwkJBMSNNURZo0im0veTMLUvqH6plQmOaVna2o2VOhJqftihA80Q1ufWuXWGGSYQpPjXC7TRhXKkDB25rOTmBqKccp0XjyDmVBKuW8qsd785RQzfUPedYtZG9Z2fto5Y4uSc0xTGO5NhcXAch8D9U+fQEDEjRr+DNSXmd/rVEM0GW6Zx5/B0gyl5c/zrwuvwpY+zDHtf7ASHSFYE0FsNbU/Hhnx/r3l4ox9SyDcWfVIJbPEl83jRHo7crFIZStLmxqYYMpwDn/BpHNvhCjjhLCezv0fcStRS0aO1CZMyWt+uoNd+SFZQ+GXow=='}
    dhl.utapi(c_cookie)
    # dhl.jihuo_cookie(t=False)
    # dhl.utapi()







